var flag = 0;
function validForm(){
    flag = 0;
    var username = document.getElementById("name").value;
    var email = document.getElementById("emailAddress").value;
    var message = document.getElementById("message").value;
    checkName(username);
    checkEmail(email);
    checkMessgae(message);
    if (flag == 0) {
        alert("请大侠稍等片刻，不才即刻遍与大侠联系！\n");
        location = location
    }else{
        return false;
    }
}
function checkName(username){
    var msg = "";
    if(username.length == 0){
        msg += "大侠请留下大名！\n";
        flag += 1;
    }else if(username.length < 6 || username.length > 20){
        msg += "大侠大名长度要在6-20之间哦！\n";
        flag += 1;
    }
    document.getElementById("label1").innerHTML = msg;
}
function checkEmail(email){
    var msg = ""
    var apos = email.indexOf("@");
    var dotpos = email.indexOf(".");
    if(email.length == 0){
        msg += "大侠留下邮箱，方便联系哦！\n";
        flag += 1;
    }else{
        if(apos == -1 ){
            if(dotpos == -1 ){
                msg += "邮箱格式错误，缺少@和.！\n";
                flag += 1;
            }else{
                msg += "邮箱格式错误，缺少@！\n";
                flag += 1;
            }
        }else if(apos == 0){
            msg += "格式错误,@不能开头\n";
            flag += 1;
        }else{
            if(dotpos == -1 ){
                msg += "邮箱格式错误，缺少.！\n";
                flag += 1;
            }else if(dotpos-apos <= 1){
                msg += "邮箱格式错误,@和.不能相邻\n"
                flag += 1;
            }
        }
    }
    document.getElementById("label2").innerHTML = msg;
}
function checkMessgae(message){
    var msg ="";
    if(message.length == 0){
        msg += "请大侠不吝赐教！\n";
        flag += 1;
    }
    document.getElementById("label3").innerHTML = msg;
}